import 'package:flutter/material.dart';
import 'package:getwidget/getwidget.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/widgets/dialogs/addToFolderDialog.dart';
import 'package:ichinesereader/widgets/dialogs/newOrEditFolderDialog.dart';
import 'package:ichinesereader/widgets/dialogs/simpleAlertDialog.dart';
import 'package:ichinesereader/constants.dart';
import '../../models/book/BookItem.dart';
import 'package:ichinesereader/pages/teacher/homeworkStepper.dart';

class TextbookBar extends StatelessWidget {
  const TextbookBar({
    Key? key,
    required this.selected,
    required this.selectedBookList,
  }) : super(key: key);
  final List<String> selected;
  final List<BookItem> selectedBookList;

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.end,
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: GFIconButton(
            color: Theme.of(context).primaryColorDark,
            onPressed: () {
              showGeneralDialog(
                  context: context,
                  transitionDuration: Duration(milliseconds: 400),
                  pageBuilder: (bc, ania, anis) {
                    return NewOrEditFolderDialog(
                        title: 'Create Lesson Plan'.tr,
                        message: '',
                        type: 'create');
                  });
            },
            icon: Icon(
              Icons.create_new_folder_outlined,
              color: Get.isDarkMode
                  ? Colors.black
                  : Theme.of(context).primaryColorLight,
            ),
            tooltip: 'Create Lesson Plan'.tr,
            size: GFSize.SMALL,
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: GFIconButton(
            color: Theme.of(context).primaryColorDark,
            onPressed: () {
              if (selected.length > 0) {
                showGeneralDialog(
                    context: context,
                    transitionDuration: Duration(milliseconds: 400),
                    pageBuilder: (bc, ania, anis) {
                      return AddToFolderDialog(
                          readingType: NanhaiBookReadingTypes.textbook,
                          title: 'Add to Lesson Plan'.tr,
                          selected: selected,
                          message: '',
                          readingTypeFrom: 'textbook');
                    });
              } else {
                showGeneralDialog(
                    context: context,
                    transitionDuration: Duration(milliseconds: 400),
                    pageBuilder: (bc, ania, anis) {
                      return SimpleAlertDialog(
                          title: '',
                          message:
                              'Please select at least one book to ADD!'.tr);
                    });
              }
            },
            tooltip: 'Add to Lesson Plan'.tr,
            icon: Icon(
              Icons.my_library_add_outlined,
              color: Get.isDarkMode
                  ? Colors.black
                  : Theme.of(context).primaryColorLight,
            ),
            size: GFSize.SMALL,
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: GFIconButton(
            color: Theme.of(context).primaryColorDark,
            onPressed: () {
              if (selected.length > 0) {
                Get.to(() => HomeworkSteps(
                      isNew: true,
                      books: selectedBookList,
                    ));
              } else {
                showGeneralDialog(
                    context: context,
                    transitionDuration: Duration(milliseconds: 400),
                    pageBuilder: (bc, ania, anis) {
                      return SimpleAlertDialog(
                          title: 'No Book'.tr,
                          message:
                              'Please select at least one book to ADD!'.tr);
                    });
              }
            },
            tooltip: 'Create Homework'.tr,
            icon: Icon(
              Icons.assignment,
              color: Get.isDarkMode
                  ? Colors.black
                  : Theme.of(context).primaryColorLight,
            ),
            size: GFSize.SMALL,
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(8.0),
        ),
      ],
    );
  }
}
